<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>收银宝</title>
		<link rel="stylesheet" href="dist/css/layui.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/shouy.css" />
		<style>
			.np_price{
			    color: #000000;
			    height: 45px;
			    border: 0;
			    width:200px;
			    border-radius: 25px;
			    background: #F0F0F0;
			    font-size: 14px;
			    line-height: 45px;
			    text-align: center;
			}
			.mui-popup-input textarea{margin-top: 5px;height: 100px; display: block; width: 90%; font-size: 14px;}
			.mui-popup-input textarea{padding: 5px;}

			.mui-popup-text{font-size: 16px; line-height: normal; padding-bottom: 5px; text-align: left;}
			.mui-popup-inner{position: relative; padding: 25px 15px 0; border-radius: 13px 13px 0 0; background: white;}
			.mui-popup {position: fixed; z-index: 10000; top: 50%; left: 50%; display: none; overflow: hidden; width: 370px; -webkit-transition-property: -webkit-transform, opacity; transition-property: transform, opacity; -webkit-transform: translate3d(-50%, -50%, 0) scale(1.185); transform: translate3d(-50%, -50%, 0) scale(1.185); text-align: center; opacity: 0; color: #000; border-radius: 13px;}
			.mui-popup.mui-popup-in {display: block; -webkit-transition-duration: 400ms; transition-duration: 400ms; -webkit-transform: translate3d(-50%, -50%, 0) scale(1); transform: translate3d(-50%, -50%, 0) scale(1); opacity: 1;}
			.mui-popup-buttons {position: relative; border-top: 1px solid #E6E6E6; display: -webkit-box; display: -webkit-flex; display: flex; height: 44px; -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center;}
			.mui-popup-button {font-size: 17px; line-height: 44px; position: relative; display: block; overflow: hidden; box-sizing: border-box; width: 50%; float: left; height: 44px; padding: 0 5px; cursor: pointer; text-align: center; white-space: nowrap; text-overflow: ellipsis; color: #007aff; background: white; -webkit-box-flex: 1; *width: 46%; *float: left;}			
			.mui-popup-button:first-child {border-radius: 0 0 0 13px; border-left: 1px solid #E6E6E6;}
			.mui-popup-button:last-child {border-radius: 0 0 13px;}
			.mui-popup-button.mui-popup-button-bold {font-weight: 600;}
			.mui-popup-backdrop {position: fixed; z-index: 998; top: 0; right: 0; bottom: 0; left: 0; -webkit-transition-duration: 400ms; transition-duration: 400ms; opacity: 0; background: rgba(0, 0, 0, .4); *background: #000000; *opacity:0.9; *filter:alpha(opacity=9);}
			.mui-popup-backdrop.mui-active {opacity: 1;}
			.hx_ft{margin-right: 2rem;}
		</style>
	</head>

	<body>
		<div class="wrap">
			<div class="sy_header clearfix">
				<div class="sy_hleft">
					<ul class="sy_nav clearfix">
						<li class="active">
							<a href="index.html">
								<div class="iconfont icon-shouyintai"></div>
								<p>工作台</p>
							</a>
						</li>
						<li>
							<a href="orders.html">
								<div class="iconfont icon-saomashouyin"></div>
								<p>订单流水</p>
							</a>
						</li>
						<li>
							<a href="yd.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>预定管理</p>
							</a>
						</li>
						<li>
							<a href="jiaoban.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>交班</p>
							</a>
						</li>
						<li>
							<a href="set.html">
								<div class="iconfont icon-weibiaoti-"></div>
								<p>设置</p>
							</a>
						</li>
					</ul>
				
				</div>
				<div class="sy_hright">
					<div class="sy_shopbox">
						<div class="sy_simg"><img id="toux" src="" style="background-color: #FFFFFF;"></div>
						<div class="sy_sinfo">
							<p class="sy_snam">店名：<span id="sname"></span></p>
							<p>用户：<span id="user"></span></p>
							<p class="exit" onclick="exit()">退出登陆</p>
						</div>
					</div>
				</div>
				
			</div>
			<div class="sy_conbox clearfix">
				<div class="sy_fleft">
					<div class="sy_flbox">
						<ul class="sy_ul">
							<li><a href="work.html"><img src="img/w1.png" style="width: 100px;"/><p>收款</p></a></li>
							<li><a href="orders.html">
								<img src="img/w2.png"/>
								<p>退款</p></a>
							</li>
							<li onclick="$('#card_cz').show()">
								<img src="img/w4.png"/>
								<p>会员充值</p>
							</li>
							<li onclick='house()'>
								<img src="img/w3.png"/>
								<p>房券核销</p>
							</li>
						</ul>
						
					</div>
				</div>
				<div class="sy_fright">
					<div class="sy_frbox">
						<div class="sy_frbt">代办事项</div>
						<p>暂无</p>
					</div>
				</div>
			</div>
				<div class="bt_name">鸿运集团酒店欢迎您</div>
		</div>
		
		<!--会员卡核销-->
		<div id="house_hx" style=" position: relative; width: 960px;display: none; ">
		<div class="mui-popup mui-popup-in" style="display: block;">
			<div class="mui-popup-inner">
				<div class="mui-popup-text" style="text-align: center;">房券核销</div>
				<div class="mui-popup-text" style="color: red;padding: 5px 3px;font-size: 14px;" id='tips' >温馨提示：请会员出示动态会员码,打开鸿运酒店公众号-我的-会员码</div>
				<div class="mui-popup-input"><input class="layui-input" id="no" placeholder="请会员出示会员卡二维码/输入订单号"/></div>
				<div id='userhouse'>
					
				</div>
			</div>
			<div class="mui-popup-buttons clearfix"><span class="mui-popup-button" onclick="card_hide(1)">取消</span><span onclick="get_userinfo()" class="mui-popup-button mui-popup-button-bold">确认核销</span></div>
		</div>
		<div class="mui-popup-backdrop mui-active" style="display: block;"></div>
		</div>
		
		
		<!--会员卡充值-->
		<div id="card_cz" style=" position: relative; width: 960px;display: none; ">
		<div class="mui-popup mui-popup-in" style="display: block;">
			<div class="mui-popup-inner">
				<div class="mui-popup-text" style="text-align: center;">会员卡充值</div>
				<div class="mui-popup-text" style="text-align: left;display: none;" id='ys_money'>应收金额:￥<em id="card_price"> </em></div>
				<div class="mui-popup-text" style="color: red;padding: 5px 3px;font-size: 14px;" id='card_ts'>温馨提示：请会员出示动态会员码,打开鸿运酒店公众号-我的-会员码</div>
				<div class="mui-popup-input"><input class="layui-input" id="no2" placeholder="请输入或扫描动态会员码"/></div>
				<div class="mui-popup-input" style="display: none;" id="card_fkm"><input class="layui-input" id='card_fk' placeholder="付款码"/></div>
				<div id="card_msg" style="display: none;">
					<div class="mui-popup-input" style="margin-top:15px"><input class="layui-input" id="cz_money" placeholder="请输入充值金额"/></div>
				</div>
			</div>
			<div class="mui-popup-buttons clearfix"><span class="mui-popup-button" onclick="card_hide(2)">取消</span><span onclick="get_userinfo()" class="mui-popup-button mui-popup-button-bold" id='card_bun'>确认充值</span></div>
		</div>
		<div class="mui-popup-backdrop mui-active" style="display: block;"></div>
		</div>
		
	
		<input type="hidden" id='user_id' />
		<input type="hidden" id='type' value=1 />
		<input type="hidden" id='order_sn' value='' />
	</body>

</html>
<script type="text/javascript" src="dist/jquery-1.11.0.min.js"></script>
<script src="dist/json2.js"></script>
<script src="dist/layui.all.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
	document.onkeydown = function(e) {
	//捕捉回车事件
	 var ev = (typeof event!= 'undefined') ? window.event : e;
	 if(ev.keyCode == 13) {
	  get_userinfo();
	 }
	}
	var isFrist=true;
	function get_userinfo(){
		var user_id = $('#user_id').val();
		var type=$('#type').val();
		var no =$('#no').val();
		var no2 =$('#no2').val();
		if(!no && !no2){
			layer.msg('会员码不可为空');
			return;
		}
		if(!no && no2.length>0){
			type=2; 
			$('#type').val(2);
		}
		
		if(Number(user_id)>0 && Number(type)==1){
			hengx();
			return;
		}else if(Number(user_id)>0 && Number(type)==2){
			chongzi();
			return;
		}
		if(type==1){//会员卡核销
			card_userhouse();
		}else if(type=2){//会员卡充值
			card_usercz();
		}
		
	}
	//房台核销
	function house(){
		$('#house_hx').show();
	}
	
	//核销
	function hengx(){
		hx_num = $('#hx_num').val();
		if(hx_num=='' || hx_num==null){
			layer.msg('请输入用户核销房券数量');
			return;
		}
		if(isFrist==true){
			isFrist=false;
			$.ajax({
				type:'post',
				url: APP.api_url + "Index/get_hengx",
				data: $('#hx_house').serialize(),
				success: function(data) {
					if(data.code==200){
						$('#user_id').val(0);
						$('#userhouse').hide();
						$('#house_hx').hide();
						$('#tips').show();
						$("#no").val('');
						jz_common(data,0);
					}else{
						layer.msg(data.msg);
					}
					isFrist=true;
				}
			})
		}else{
			layer.msg('请勿频繁操作！');
		}
		
	}
	
	//会员卡核销前查询数据
	function card_userhouse(){
		$.ajax({
			url: APP.path + "index/get_userhouse",
			type:"POST",
			data: {
				no: $('#no').val(),
				app_id: APP.app_id,
				store_id: getValue("store_name_id"),
				time: Date.parse(new Date())
			},
			success: function(data) {
				if(data.code!=200){
					layer.msg(data.msg);
				}else{
					console.log('会员卡核销');
					$('#tips').hide();
					userhouse = data.userhouse;
					$('#user_id').val(userhouse[0]['user_id']);
					var is_no='';
					var disabled = '';
					if(data.is_no==1){
						is_no = userhouse[0]['num'];
						disabled = 'disabled=disabled';
					}
					var str='<form class="layui-form" id="hx_house" name="myForm">';
						str+='<input type="hidden" name="user_id" value='+userhouse[0]['user_id']+' />';
						str+='<input type="hidden" name="store_id" value='+userhouse[0]['store_id']+' />';
						str+='<input type="hidden" name="is_no" value='+data.is_no+' />';
						str+='<input type="hidden" name="staff_id" value='+getValue("id")+' />';
					$.each(userhouse,function(i,log){
						str+='<div class="mui-popup-text2">'+
							'<span class="hx_ft"><em>'+log['h_name']+'</em>：'+log['num']+'间</span>'+
							'<div class="left"><input class="layui-input" name="hx_num[]"  value="'+is_no+'"  id="hx_num" name="hx_num[]" placeholder="请输入本次核销数量" '+disabled+'></div>'+
							'<div class="left"><input type="hidden"  name="hx_id[]"  id="hx_id" value='+log['id']+' ></div>'+
							'</div>';
					});
					str+= '</form>';
					$('#userhouse').html(str);
					$('#userhouse').show();
				}
			}
		})
	}
	
	//会员卡充值前查询
	function card_usercz(){
		$.ajax({
			url: APP.path + "index/get_userinfo",
			type:"POST",
			data: {
				no: $("#no2").val(),
				app_id: APP.app_id,
				time: Date.parse(new Date()),
				store_id:getValue('store_name_id')
			},
			success: function(data) {
				console.log(data);
				if(data.code!=200){
					layer.msg(data.msg);
					return;
				}else{
					$('#card_ts').hide();
					var user=data.user;
					$("#user_id").val(user.id);
					$("#card_msg").show();
				}
			}
		})
	}
	
	//充值
	function chongzi(){
		order_sn = $('#order_sn').val();
		if(order_sn){
			//确认收款
			card_que();
			return;
		}
		cz_money = $('#cz_money').val();
		if(cz_money=='' || cz_money==null){
			layer.msg('请输入充值金额');
			return;
		}
		
		$.ajax({
			type:'post',
			url: APP.api_url + "Index/card_cz",
			data: {
				store_id: getValue("store_name_id"),
				user_id:$('#user_id').val(),
				cz_money :cz_money,
				staff_id:getValue('id'),
			},
			success: function(data) {
				if(data.code==400){
					layer.msg(data.msg);
					return false;
				}
				$('#order_sn').val(data.order_sn);
				$('#ys_money').show();
				$('#card_msg').hide();
				$('#card_fkm').show();
				$('#card_price').text(cz_money);
				$('#card_bun').text('确认收款');
			}
		})
	}
	
	//会员卡充值确认付款
	function card_que(){
		var mem_card = $("#card_fk").val();
		if(mem_card == "") {
			layer.msg("付款码不可为空!");
			return false;
		}
		if(isFrist==true){
			isFrist=false;
			$.ajax({
				type:'post',
				url: APP.api_url + "Index/card_que",
				data: {
					store_id: getValue("store_name_id"),
					user_id:$('#user_id').val(),
					order_sn:$('#order_sn').val(),
					staff_id:getValue('id'),
					mem_card:mem_card
				},
				success: function(data) {
					if(data.code==200){
						$('#type').val(1);
						$('#card_cz').hide();
						$('#ys_money').hide();
						$('#card_msg').show();
						$('#card_fkm').hide();
						$('#no2').val('');  //会员码为空
						$('#card_msg').hide(); //充值文本框
						$('#card_ts').show();  //提示语
						$('#user_id').val(0);
						$('#order_sn').val('');
						cz_money =$('#cz_money').val();
						$('#cz_money').val('');
						jz_common(data,cz_money);
					}else{
						layer.msg(data.msg);
					}
					isFrist=true;
				}
			})
		}else{
			layer.msg('请勿频繁操作！');
		}
		
	}
	
	
	/**
	 * 关闭充值或者核销窗口操作
	 * type 1 核销   2充值
	 * */
	function card_hide(type){
		$('#no2').val('');  //会员码为空
		$('#no').val('');
		$('#user_id').val(0);
		if(type==1){
			$('#tips').show();
			$('#house_hx').hide();
			$('#userhouse').hide();
		}else if(type==2){
			$('#type').val(1);
			$('#card_cz').hide();
			$('#ys_money').hide();
			$('#card_msg').show();
			$('#card_fkm').hide();
			$('#card_msg').hide(); //充值文本框
			$('#card_ts').show();  //提示语
			$('#user_id').val(0);
			$('#order_sn').val('');
			$('#cz_money').val('');
			$('#card_cz').hide();
		}
	}
</script>
